/**
 * Created by yangfan on 2016/10/21.
 */
define([],function(){
    var utils = {
		getFileType:function(item,key){
			var str = 'other';
			var obj = {
				word:['doc','docx','dot','dotx','docm','wps','wpt'],
				xls:['xls','xlt','xlsx','xlsb','xlsm','xlst','et','ett'],
				ppt:['pptx','ppt','pptm','potx','pot','potm'],
				cad:['dwg','dws','dwt','dxf'],
				pdf:['pdf'],
				other:['rar','swf','jpg','jpeg','txt','caj','rtf']
			}
			function getType(){
				var flag = false,type;
				for(var key in obj ){
					flag =	obj[key].filter(function(child,index,array){
						type = key ;
						return child == item
					})
					if(flag[0] !=undefined){
						return type
					}
				}
			}
			var ret = getType();
			return ret ;
		},
    	 removeArray:function(Arr,item,key){
    	 		var index = Arr.indexOf(item);
                	if(index>-1){
                		Arr.splice(index,1);
                	}
                	return Arr;      	
        },
        checkArray:function(Arr,item,key){
        	for(var i = 0;i<Arr.length;i++){
	 			for(var j = 0;j<item.length;j++){
	 				if(Arr[i] == item[j]){
	 					Arr.splice(i,1);
	 				}
	 				
	 			}
	 		}
        	return Arr;
        },
		removeArrayKey:function(Arr,item,key){
			if(key&&toString.call(key) == '[object String]'){
				if(!item.hasOwnProperty(key)){
					return
				};
				var ret = Arr.filter(function(child,index,array){
					return (child[key]!=item[key])
				});
				return ret
			};
		},
		getArrayIndex:function(Arr,item,key){
			if(toString.call(Arr)!="[object Array]"){
				return
			};
			var i;
			 Arr.filter(function(child,index,array){
				if(child[key] == item[key]){
					return i = index
				}
			})
			return i
		},
		isArrayContain:function(Arr,item,key){
		return  Arr.some(function(child,index,array){
			return child[key] == item[key]

		})
	   },
		//判断对象是否为空 可以甄别 null  与 {}
		isOwnEmpty:function (obj) {
		for(var name
			in obj)
		{
			if(obj.hasOwnProperty(name))
			{
				return false;
			}
		}
		return true;
	  },
		//getMulti函数 作用为将Arr数组中与obj 对象对应的属性赋值给obj，最后obj 子属性返回每一项字符串 用","连接   @Arr @obj  ！
        getMulti:function(Arr,obj){
          		if( toString.call(Arr) != '[object Array]'||toString.call(obj) != '[object Object]'){
               			 return ""
           			}; 
           			Arr.forEach(function(item,index,array){
           				for(var key in obj ){
           					obj[key].push(item[key]);
           				}         				
           			});    
           			for(var key in obj ){
           					obj[key] = obj[key].join(",") ;
           			} 
           				
           				return obj ;
            	},
		getShowValue:function(Arr,key){
			if( toString.call(Arr) != '[object Array]'||toString.call(key) != '[object String]'){
				return ""
			};
			var reArr = [] ;
			Arr.forEach(function(item,index,array){
				reArr.push(item[key]);
			});
			return reArr.join("+")
		},
		getJobConf: function(input){
			if(toString.call(input) != '[object Array]' ){
				return
			}
			var arr = [] ;
			input.forEach(function(item ,index,array){
				arr.push( item.fdcName)
			});
			return arr.join("+");
		},
		getIndustry:function(input){
		if(toString.call(input) != '[object Array]' ){
			return
		}
		var arr = [] ;
		input.forEach(function(item ,index,array){
			arr.push( item.dictName)
		})
		return arr.join("+");
	},
		getIntentionRegion:function(input){
			if(toString.call(input) != '[object Array]' ){
				return
			}
			var arr = [] ;
			input.forEach(function(item ,index,array){
				var  str = item.ewpRegionObject.regionName + "" + item.ewpAreaObject.areaName;
				arr.push(str)
			})
			return arr.join("+");
		},
		ew2ReValue:function (arr){
		if(toString.call(arr) != '[object Array]' ){
			return
		};
		var obj = {
			provinceId:"",
			regionId:"",
			areaId:"",
			regionName:""
		},reArr = [];
		arr.forEach(function(item ,index,array){
			obj.provinceId = item.ewpProvinceId;
			obj.regionId = item.ewpRegionId;
			obj.areaId = item.ewpAreaId;
			obj.regionName = item.ewpRegionObject.regionName;
			reArr.push(obj);
		});
		return reArr;
	},
		getRegion:function(obj){
		if(toString.call(obj) !="[object Object]"){
			return
		};
			if(!obj.region){
				return
			}
		var obj = {
			provinceId:obj.region.provinceId,
			regionId:obj.region.regionId,
			areaId:obj.area.areaId,
			regionName:obj.region.regionName
		};
		return obj;
	},
		getHtPlace:function(obj){
		if(toString.call(obj) !="[object Object]"){
			return
		};
			if(!obj.provice){
				return
			}
			var obj = {
				provinceId:obj.provice.provinceId,
				regionId:obj.region.regionId,
				areaId:obj.area.areaId,
				regionName:obj.region.regionName
			};
			return obj ;
		},
		getCard:function(input){
		if(toString.call(input) != '[object Object]' ){
			return
		}
		if(input.cardId ==1){
			return input.cardNumber
		}
	},
		getYMD:function(input){
		if(toString.call(input) != '[object String]' ){
			return
		}
		var str = input.substr(0,input.lastIndexOf(" ")) ;
		var ret = str.replace(/-/g,"/");
		return ret
	},
		YMD2YMD:function(input){
			if(toString.call(input) != '[object String]' ){
				return
			}
			if(input.indexOf("/")<0){
				return
			}
			var ret = input.replace(/[\/]/g, "-");
			return ret
		},
		getMultiRegion :function(Arr){
			if( toString.call(Arr) != '[object Array]'){
				return
			};
			var reArr = [];
			Arr.forEach(function(item,index,array){
				var obj = {
					ewpProvinceId:item.provinceId,
					ewpRegionId:item.regionId,
					ewpAreaId:item.areaId
				};
				reArr.push(obj);
			});
			reArr = JSON.stringify(reArr);
			return reArr ;
		},
		getPlace:function(input){
			if(toString.call(input) != '[object Object]' ){
				return
			}
			return input.region.regionName + " " + input.area.areaName
		},
		getDoubleLan:function(input){
			if(toString.call(input) != '[object Array]' ){
				return
			}
			var reArr = [];
			input.forEach(function(item){
				reArr.push(item.laug.name+ "-"+ item.lgrade.name)
			});
			return reArr.join(",");
		},
		functionIds:function (arr){
		if(toString.call(arr) != '[object Array]'){
			return {id:""}
		};
		var temArr = [],showArr = [];
		arr.forEach(function(item ,index ,array){
			temArr.push(item.fdcId);
			showArr.push(item.fdcName);
		});
		return {
			id:temArr.join(","),
			area:showArr.join(",")
		}
		},
		//根据汉字 字母不同返回长度  汉字算一个  两个字母算一个
		getContentLength:function (str) {
			//if(toString.call(str) != 'object String'){
			//	return
			//}
			if(!str){
				str = '';
			}
		var len = 0;
		var strLen = str.length;
		for (var i = 0; i < strLen; i++) {
			var c = str.charCodeAt(i);
			//单字节加1
			if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
				len++;
			}
			else {
				len += 2;
			}
		}
			len = Math.ceil(len/2);
		return len;
    	},
		getTags:function(arr,split){
			if(toString.call(arr) != '[object Array]' ){
				return
			};
			var ret = [];
			arr.forEach(function(item,index){
				ret.push(item.name)
			})
			return ret.join(split);
		},
		getKey:function(arr,split,key){
			if(toString.call(arr) != '[object Array]' ){
				return
			};
			var ret = [];
			arr.forEach(function(item,index){
				ret.push(item[key])
			})
			return ret.join(split);
		},
		//得到一个纯数组队列
		getIdsArray :function(array,key){
			if(toString.call(array) != '[object Array]' ){
				return
			};
			var ret =[];
			array.forEach(function(item,index){
				ret.push(item[key])
			})
			return ret ;
		},
		transferSpace:function(str){
			if(toString.call(str) != '[object String]' ){
				return
			};
			var ret ;
			//str = str.replace(/\s+/g, ' ');
			ret = (str.replace(/\s+/g, ' ')).replace(" ",',')
			return ret ;
		},
		//获取html 标签内内容
		contentConvert:function(content){
		if(toString.call(content)!= "[object String]"){
			return
		}
		var ret ;
		ret = content.replace(/(<.*?>)*/g,"")
		return ret ;
		},
		timeTransfer:function(time){
			if(toString.call(time)!='[object String]'){
				return
			}
			return time.replace(/\//g,'-')
		},
	clearDateSpace:function(input){
				if(toString.call(input) != '[object String]' ){
					return
				}
				return input.substring(0,input.indexOf(" "));
		}
		};
    return utils;
});